package com.scs.application.modules.fsd.controller;

import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.modules.fsd.entity.FsdChestChestGroup;
import com.scs.application.modules.fsd.service.ChestChestGroupService;
import com.scs.application.modules.sys.model.RestResult;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Description: 柜组管理
 */
@RestController
@RequestMapping("/back_front/chests_chestGroups")
public class ChestChestGroupController extends CrudController<ChestChestGroupService, FsdChestChestGroup> {

    /**
     * 获取数据列表
     */
    @GetMapping(value ="/getChestGroupsByChestService" )
    public RestResult getChestGroupsByChest(@RequestParam("id") String id) {
        return RestResult.ok("获取该智能柜所在的智能柜组成功",service.getChestGroupsByChest(id));
    }

    @PostMapping(value = "/changeChestGroupsByChestService")
    public RestResult changeChestGroupsByChest(@RequestBody Map<String, String> map){
        if(service.changeChestGroupsByChest(StringUtils.stringArryExtract(map.get("idAry"),"chestGroupId"),map.get("id")))
            return RestResult.ok("保存成功！");
        return RestResult.error("保存失败！");
    }

    @GetMapping(value ="/getChestsAndStationsByChestGroupService" )
    public RestResult getChestsAndStationsByChestGroup(@RequestParam("id") String id) {
        return RestResult.ok("获取该智能柜所在的智能柜组成功",service.getChestsAndStationsByChestGroup(id));
    }

    @PostMapping(value = "/changeChestsByChestGroupService")
    public RestResult changeChestsByChestGroup(@RequestBody Map<String, String> map){
        if(service.changeChestsByChestGroup(StringUtils.stringArryExtract(map.get("idAry"),"chestId"),map.get("id")))
            return RestResult.ok("保存成功！");
        return RestResult.error("保存失败！");
    }
}
